package cn.zhibang.yygh2.common.util.util;

import org.apache.commons.codec.binary.Base64;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class ImageBase64Util {
    public static String getImageString(String imageFile){
        InputStream is = null;
        try {
            byte[] data = null;
            is = new FileInputStream(new File(imageFile));
            data = new byte[is.available()];
            is.read(data);
            return new String(Base64.encodeBase64(data));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != is) {
                try {
                    is.close();
                    is = null;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return "";
    }
    // 测试将一张图片转换成Base64编码
    public static void main(String[] args) {
        String logo = getImageString("F:\\微医项目\\0718_yygh项目_01\\医疗实战项目\\01_文案\\湘雅医院logo.jpg");
        System.out.println(logo);
    }
}
